//
//  XSImageGridView.m
//  AudioVideo
//
//  Created by xueshan1 on 2019/9/25.
//  Copyright © 2019 xueshan1. All rights reserved.
//

#import "XSImageGridView.h"

@implementation XSImageGridView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)setClipRect:(CGRect)clipRect{
    _clipRect = clipRect;
    [self setNeedsDisplay];
    
}

- (void)drawRect:(CGRect)rect {
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [[UIColor blackColor]colorWithAlphaComponent:0.5].CGColor);
    CGContextFillRect(context, rect);
    
    CGContextClearRect(context, self.clipRect);
    
    //line
    CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
    CGContextSetLineWidth(context, 1);
    CGContextBeginPath(context);
    CGFloat x = self.clipRect.origin.x;
    CGFloat y = self.clipRect.origin.y;
    CGFloat w_margin = self.clipRect.size.width/3;
    CGFloat h_margin = self.clipRect.size.height/3;
    for (int i = 0; i<4 ; i++) {
        CGContextMoveToPoint(context, x, y + i*h_margin);
        CGContextAddLineToPoint(context, x + self.clipRect.size.width, y + i*h_margin);
    }
    
    for (int i = 0; i<4; i++) {
        int d = 0;
        if (i == 0) {
            d = 0.5;
        }else if (d == 3){
            d = -0.5;
        }
        CGContextMoveToPoint(context, x + i*w_margin +d , y);
        CGContextAddLineToPoint(context, x + i*w_margin +d , y + self.clipRect.size.height);
    }
    CGContextStrokePath(context);
    
    
}

@end
